package com.dxy.dxyuser.repository;

import com.dxy.dxyuser.DO.UserInfo;
import feign.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

public interface UserInfoRepository extends JpaRepository<UserInfo,String> {

    /**
     * 通过姓名查询用户信息
     * @param username
     * @return
     */
    UserInfo findByUsername(String username);

    @Query(value = "FROM UserInfo u WHERE u.username LIKE %:username% AND u.phone LIKE %:phone% AND u.createTime between :start and :end ")
    Page<UserInfo> findByUsernameLikeAndPhoneLikeAndCreateTimeBetween(@Param("username") String username,
                                                                      @Param("phone") String phone,
                                                                      @Param("start")Date start,
                                                                      @Param("end")Date end, Pageable pa);

    @Query(value = "FROM UserInfo u WHERE u.username LIKE %:username% AND u.phone LIKE %:phone% ")
    Page<UserInfo> findByUsernameLikeAndPhoneLike(@Param("username")String username,
                                                  @Param("phone")String phone, Pageable pa);
}
